package Chapter6;

public class BinaryTrees {
    private static int i=0;

    public static BinaryTree<String> createByGenList(String genList){
        BinaryTree<String> bitree=new BinaryTree<String>();
        i=0;
        bitree.root=create(genList);
        return bitree;
    }

    public static BinaryNode<String> create(String genList){
        BinaryNode<String> p=null;
        if (i<genList.length()){
            char ch=genList.charAt(i);
            i++;
            if (ch=='^')
                return null;
            p=new BinaryNode<String>(ch+"");
            if (i<genList.length()&&genList.charAt(i)=='('){
                i++;
                p.left=create(genList);
                i++;
                p.right=create(genList);
                i++;
            }
        }
        return p;
    }

}
